#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

void kot(int& ret, unordered_map<int, int>& exit, unordered_map<int, int>& hash, vector<int>& a, int n)
{
    if (n == a.size())
    {
        int tmp = 0;
        for (auto& [x, y] : exit) tmp += x;
        ret = min(ret, tmp);
        return;
    }

    for (int i = 2; i <= a[n]; i++)
        if (a[n] % i == 0 && hash.count(i) && exit.count(i) == 0)
        {
            exit[i];
            kot(ret, exit, hash, a, n + 1);
            exit.erase(i);
        }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    unordered_map<int, int> hash;
    for (int i = 2; i < 1000; i++)
    {
        bool bl = true;
        for (int j = 2; j * j <= i; j++)
            if (i % j == 0)
            {
                bl = false;
                break;
            }
        if (bl) hash[i] = 1;
    }
    for (int i = 0; i < n; i++) cin >> a[i];
    unordered_map<int, int> exit;
    int ret = 10000;
    kot(ret, exit, hash, a, 0);
    if (ret == 10000) cout << -1;
    else cout << ret;
    return 0;
}